<?php
$caption = BUtils::T('template_offer_lbl');
$this->pageTitle = Yii::app()->name . ' - ' . $caption;

$special_list_btn = BUtils::T('special_list_view_lbl');
$create_template_btn = BUtils::T('template_create_lbl');
$create_instant_special_btn = BUtils::T('special_create_instant_btn');
$create_long_special_btn = BUtils::T('special_create_plan_btn');
$edit_btn = BUtils::T('edit_btn');
?>
<div class="container prepend-top">
	<?php echo CHtml::button('< ' . BUtils::T('back_btn'), array('class'=>'button', 'onclick'=>"history.go(-1)")); ?>
</div>

<div class="container prepend-top append-bottom">
	
	<div class="span-17">
		<div class="box_white">
			<div class="biz-form">
				<div class="margin">
					<div class="right">
						<?php echo CHtml::button($create_template_btn, array('class'=>'button button-huge button-compliment', 'id'=>'create_new_template')) ?>
					</div>
					<div>
						<h3><?php echo $caption; ?></h3>
						<div class="tips"><?php echo BUtils::T('template_offer_eg'); ?></div>
					</div>
					<div class="clear"></div>
				</div>
				
				<div class="fieldswrap">
					<div class="mobile">
<div id="special-list">
	<table class="va-top">
<?php
foreach ($rows as $k => $row) {
	$url_thumb = BUtils::GetOfferThumbUrl($row['url_picture']);
	
	$discount_text = null;
	if (!empty($row['discount'])) {
		$discount_text = '-' . round($row['discount']*100) . '%';
	}
	
	//content
	$content_text = strip_tags($row['content']);
	
	//title
	$title_text = BUtils::T('special_auto_title_lbl', array(
		'{merchant_name}' => Yii::app()->user->getState('name'),
		'{price}' => Yii::app()->locale->numberFormatter->formatCurrency($row['price'], 'EUR'),
		'{value}' => Yii::app()->locale->numberFormatter->formatCurrency($row['value'], 'EUR'),
	));
?>
<tr>
	<td class="discount-field">
		<a class="pic"><img src="<?php echo $url_thumb; ?>" width="96" alg="" /></a>
	</td>
	<td class="title-field">
		<div class="title"><?php echo $content_text; ?></div>
		<div class="address"><?php echo $title_text; ?></div>
		<div class="buttons">
			<?php echo CHtml::link("<span>{$create_instant_special_btn}</span>", Yii::app()->createUrl('/special/form', array('view' => 'instant', 'tid'=>$row['id'])), array('class'=>'button button-small button-confirm')); ?>
			<?php echo CHtml::link("<span>{$create_long_special_btn}</span>", Yii::app()->createUrl('/special/form', array('tid'=>$row['id'])), array('class'=>'button button-small button-confirm')); ?>
		</div>
	</td>
	<td class="discount-field">
		<div class="discount-box">
			<span class="special-discount"><?php echo $discount_text; ?></span>
		</div>
		<div>
			<?php echo CHtml::link("<span>{$edit_btn}</span>", Yii::app()->createUrl('/specialTemp/form', array('id'=>$row['id'])), array('class'=>'button button-small button-thin')); ?>
		</div>
	</td>
</tr>
<?php } ?>
	</table>
</div>
					</div>
				</div>
			</div>
		</div>
	</div>
	
	<div class="span-7 right last">
		<div class="box_white append-bottom">
			<div class="biz-form margin">
				<h3><?php echo BUtils::T('special_lbl'); ?></h3>
				<div class="tips"><?php echo BUtils::T('special_offer_list_eg'); ?></div>
				<hr />
				<div class="">
					<?php echo CHtml::link("<span>{$special_list_btn}</span>", Yii::app()->createUrl('/special'), array('class'=>'button button-confirm', 'rel'=>'tipsy', 'id'=>'list_template')) ?>
				</div>
			</div>
		</div>
		<?php BHelper::HtmlCompletionTips(); ?>
	</div>
</div>


<div id="dlg-template" title="<?php echo BUtils::T('account_upgrade_lbl'); ?>" style="display:none;">
	<p><?php echo BUtils::T('template_limit_num_msg', array('{num}'=>10)); ?></p>
</div>

<script type="text/javascript">
(function() {
	//check the number of template
	var maxNumber = 10;
	var curNumber = <?php echo count($rows); ?>;
	if (curNumber < maxNumber) {
		$('#create_new_template').click(function(){
			location.href = '<?php echo Yii::app()->createUrl('/specialTemp/form', array('view'=>'instant')); ?>';
		});
	} else {
		$('#create_new_template').click(function(){
			$( "#dlg-template" ).dialog({
				modal: true, resizable: false, draggable: false,
				buttons: {
					<?php echo BUtils::T('cancel_btn'); ?>: function() {
						$(this).dialog("close");
					}/*,
					<?php echo BUtils::T('confirm_btn'); ?>: function() {
						$(this).dialog("close");
					}*/
				}
			});
			return false;
		});
	}
})();
</script>